<?php




namespace app\controller\api\user;

use app\common\repositories\user\UserTalentRepository;
use crmeb\basic\BaseController;
use think\App;

class UserTalent extends BaseController
{
    protected $repository;

    public function __construct(App $app, UserTalentRepository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }

    /**
     * @return mixed
     * @author xaboy
     * @day 2020/5/28
     */
    public function talent()
    {
        $data = $this->request->params([['talent_id', 0], 'plat', ['other', ''], 'real_name', 'company', 'phone', 'email', ['expected', '']]);
        $data['uid'] = $this->request->uid();
        if ($data['talent_id']) {
            $talent = $this->repository->get($data['talent_id']);
            $talent->plat = $data['plat'];
            $talent->other = $data['other'];
            $talent->real_name = $data['real_name'];
            $talent->company = $data['company'];
            $talent->phone = $data['phone'];
            $talent->email = $data['email'];
            $talent->expected = $data['expected'];
            $talent->add_time = date('Y-m-d H:i:s');
            $talent->save();
        } else {
            $this->repository->create($data);
        }
        return app('json')->success('提交成功');
    }

    /**
     * @return mixed
     * @author xaboy
     * @day 2020/5/28
     */
    public function list()
    {
        [$page, $limit] = $this->getPage();
        return app('json')->success($this->repository->getList(['uid' => $this->request->uid()], $page, $limit));
    }

    public function detail($id)
    {
        $data = $this->repository->getWhere(['uid' => $this->request->uid()]);
        $data = $data ?: '';
        return app('json')->success($data);
    }
}
